//
//  ProblemDoneHandleViewController.m
//  Utils
//
//  Created by enghou on 2018/4/17.
//  Copyright © 2018年 xyxorigation. All rights reserved.
//

#import "ProblemDoneHandleViewController.h"

@interface ProblemDoneHandleViewController ()

@property(nonatomic,strong)NSArray *solve_ways;

@property(nonatomic,strong)NSArray *situations;

@end

@implementation ProblemDoneHandleViewController

- (void)viewDidLoad {
    [super viewDidLoad];
}

-(NSDictionary *)param{
    if ([self.limitField.text length] == 0) {
        [self alertSome:@"请选择化解时限!"];
        return nil;
    }
    if (!self.yesBtn.selected && !self.noBtn.selected) {
        [self alertSome:@"请选择是否化解成功!"];
        return nil;
    }
    if ([self.solve_id length] == 0) {
        [self alertSome:@"请选择化解方式!"];
        return nil;
    }
    if ([self.situation_id length] == 0) {
        [self alertSome:@"请选择化解情况"];
        return nil;
    }
    if ([self.continousField.text length] == 0) {
        [self alertSome:@"请输入后续工作措施!"];
        return nil;
    }
    if ([self.manageSituationField.text length] == 0) {
        [self alertSome:@"请输入调处情况!"];
        return nil;
    }
    return @{@"issueStepId":self.stepId,@"issue.handleTime":self.limitField.text,@"issue.handleSuccessed":(self.yesBtn.selected ? @"1" : @"0"),@"issue.resolvingWay.id":self.solve_id,@"issue.resolveSituation.id":self.situation_id,@"issue.followWork":self.continousField.text,@"logNew.content":self.manageSituationField.text};
}

-(NSString *)typeId{
    return @"30";
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)showDateAction:(id)sender {
    [self.dateField becomeFirstResponder];
}

- (IBAction)yesAction:(UIButton *)sender {
    sender.selected = YES;
    _noBtn.selected = NO;
}
- (IBAction)noAction:(UIButton *)sender {
    sender.selected = YES;
    _yesBtn.selected = NO;
}

-(void)cancelAction{
    [self.view endEditing:YES];
}

-(void)sureAction{
    self.limitField.text = [[self.datePicker date]dateLineStrOnlyDay];
    [self.dateField resignFirstResponder];
}

-(void)alertSolve{
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleAlert];
    for (PropertyDictItemModel *model in self.solve_ways) {
        UIAlertAction *action = [UIAlertAction actionWithTitle:model.displayName style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            self.solve_id = model.ids;
            self.solveWayField.text = model.displayName;
        }];
        [alert addAction:action];
    }
    UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    [alert addAction:cancel];
    [(BaseViewController *)self.theDelete presentViewController:alert animated:YES completion:nil];
//    [self presentViewController:alert animated:YES completion:nil];
}

-(void)alertSituation{
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleAlert];
    for (PropertyDictItemModel *model in self.situations) {
        UIAlertAction *action = [UIAlertAction actionWithTitle:model.displayName style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            self.situation_id = model.ids;
            self.solveSituationField.text = model.displayName;
        }];
        [alert addAction:action];
    }
    UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    [alert addAction:cancel];
    [(BaseViewController *)self.theDelete presentViewController:alert animated:YES completion:nil];
//    [self presentViewController:alert animated:YES completion:nil];
}
- (IBAction)showFilePicker:(id)sender {
    [super showFilePicker:sender];
}





-(void)pushToSolveWay{
    //推到化解方式
    if (!self.solve_ways) {
        [self beginLoading];
        [[NetWorkerManager sharedInstance]getPropertyDictWithDomainName:@"化解方式" successBlock:^(BaseModel *model) {
            [self endLoading];
            if (model.success) {
                self.solve_ways = model.list;
                [self alertSolve];
            }
        } failBlock:^(NSInteger code) {
            [self endLoading];
        }];
    }else{
        [self alertSolve];
    }
}

-(void)pushToSituation{
    //推到化解情况
    if (!self.solve_ways) {
        [self beginLoading];
        [[NetWorkerManager sharedInstance]getPropertyDictWithDomainName:@"化解情况" successBlock:^(BaseModel *model) {
            [self endLoading];
            if (model.success) {
                self.situations = model.list;
                [self alertSituation];
            }
        } failBlock:^(NSInteger code) {
            [self endLoading];
        }];
    }else{
        [self alertSituation];
    }
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        [self showActions];
    }else if (indexPath.row == 3){
        [self pushToSolveWay];
    }else if (indexPath.row == 4){
        [self pushToSituation];
    }
}

@end
